package com.toe.user.webapi.controller;


import com.toe.common.exception.ToeServiceException;
import com.toe.common.restful.JsonResult;
import com.toe.common.restful.StateEnum;
import com.toe.pojo.vo.user.UserFocusVO;
import com.toe.pojo.vo.user.UserSimpleVO;
import com.toe.user.service.UserFocusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户关注用户表 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/webapi")
@Api(tags = "用户关注模块")
public class UserFocusController {
    @Autowired
    private UserFocusService userFocusService;
    @GetMapping("/user-focus")
    @ApiImplicitParam(name ="focusId",value = "被关注用户的id",required = true,example = "1")
    @ApiOperation(value = "关注")
    public JsonResult<Void> focus(Long focusId){
        if (userFocusService.focus(focusId))
        return JsonResult.ok();
        else throw new ToeServiceException(StateEnum.ERR_SERVER_ERROR,"关注失败,服务器忙请稍后再试!");
    }
    @GetMapping("/get-all-focus-user")
    @ApiOperation(value = "获取所有关注的用户的信息")
    public List<UserFocusVO> getAllFocusUser() {
       return userFocusService.getAllFocusUser();
    }

    @GetMapping("/get-focus-user-detail")
    @ApiImplicitParam(name ="focusId",value = "被关注用户的id",required = true,example = "1")
    @ApiOperation(value = "获取被关注用户的信息")
    public JsonResult<UserSimpleVO> getFocusUserDetail(Long focusId){
        UserSimpleVO userDetail = userFocusService.getFocusUserDetail(focusId);
        return JsonResult.ok(userDetail);
    }
    @GetMapping("/cancel-focus")
    @ApiImplicitParam(name ="focusId",value = "取消关注的用户id",required = true,example = "1")
    @ApiOperation(value = "取消关注")
    public JsonResult<Void> cancelFocus(Long focusId){
        userFocusService.cancelFocus(focusId);
        return JsonResult.ok();
    }
}

